/**
 *  璇ュ叕鍏眏s鏂囦欢闇€瑕佹斁鍦╬ublic/global.js涓嬮潰锛屽洜涓洪渶瑕乬etCookie鏂规硶
 */
$(function(){
    get_cart_num();
    user_login_or_no();
})
/****璐墿杞� start****/
function get_cart_num() {
    var cart_cn = getCookie('cn');
    if (cart_cn == '') {
        $.ajax({
            type: "GET",
            url: "/index.php?m=Home&c=Cart&a=header_cart_list",//+tab,
            success: function (data) {
                cart_cn = getCookie('cn');
                $('#cart_quantity').html(cart_cn);
                $('#tab_cart_num').html(cart_cn);
            }
        });
    }
    $('#tab_cart_num').html(cart_cn);
    $('#cart_quantity').html(cart_cn);
    $('#miniCartRightQty').html(cart_cn);
}


var header_cart_list_over = 0;
$('#hd-my-cart').hover(function () {
    $('#show_minicart').show();
    if (header_cart_list_over == 1)
        return false;
    header_cart_list_over = 1;
    $.ajax({
        type: "GET",
        url: "/index.php?m=Home&c=Cart&a=header_cart_list",//+tab,
        success: function (data) {
            $("#hd-my-cart > #show_minicart").html(data);
            get_cart_num();
        }
    });
}, function () {
    $('#show_minicart').hide();
    (typeof(t) == "undefined") || clearTimeout(t);
    t = setTimeout(function () {
        header_cart_list_over = 0; /// 鏍囪瘑榧犳爣宸茬粡绂诲紑
    }, 2000);
});


// ajax 鍒锋柊璐墿杞︾殑鍟嗗搧
function header_cart_del(ids) {
    var id_arr = new Array();
    id_arr = ids.toString().split(","); //瀛楃鍒嗗壊
    $.ajax({
        type: "POST",
        url: "/index.php?m=Home&c=Cart&a=delete",
        data: {cart_ids: id_arr},
        dataType: 'json',
        success: function (data) {
            if (data.status == 1) {
                header_cart_list_over = 0; /// 鏍囪瘑榧犳爣宸茬粡绂诲紑
                $("#hd-my-cart").trigger('mouseenter');	 // 鏃犳硶瑙﹀彂 hover 鏀逛负 trigger('mouseenter');
                ajax_side_cart_list()  //瑙ｅ喅渚ц竟鏍忚喘鐗╄溅鐐瑰嚮鍒犻櫎鍚庝笉鑳界珛鍗虫洿鏂� lxl
            }
        }
    });
}
//渚ц竟鏍忚喘鐗╄溅
function ajax_side_cart_list() {
    $.ajax({
        type: "GET",
        url: "/index.php?m=Home&c=Cart&a=header_cart_list&template=ajax_side_cart_list",//+tab,
        success: function (data) {
            cart_cn = getCookie('cn');
            $('#cart_quantity').html(cart_cn);
            $('#tab_cart_num').html(cart_cn);
            $('.shop-car-sider').html(data);
        }
    });
}
/*******璐墿杞� end********/

/*******鐢ㄦ埛鐧诲綍鍙樺寲class****/
function user_login_or_no()
{
    var uname = getCookie('uname');
    if (uname == '') {
        $('.islogin').remove();
        $('.nologin').show();
    } else {
        $('.nologin').remove();
        $('.islogin').show();
        $('.userinfo').html(decodeURIComponent(uname).substring(0,11));
    }
}

/*******ajax 鍥剧墖鎳掑姞杞�****/
function lazy_ajax()
{
    $(".lazy").lazyload({
        placeholder : "images/white.gif",
        effect: "fadeIn",
        threshold: 20,
        vertical_only: false,
        no_fake_img_loader:true
    });
}